package com.example.project.service.impl;

import com.example.project.mapper.ArticleMapper;
import com.example.project.pojo.Article;
import com.example.project.service.ArticleService;
import com.example.project.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;
    @Override
    public List<Article> getlist() {
        List<Article> list=articleMapper.getlist();
        return list;
    }

    @Override
    public void add(Article article) {
        article.setCreateTime(LocalDateTime.now());
        article.setUpdateTime(LocalDateTime.now());
        Map<String,Object> map=ThreadLocalUtil.get();
        String name= (String) map.get("name");
        article.setUser(name);
        articleMapper.add(article);
    }

    @Override
    public List mylist(int id) {
        List<Article> list = articleMapper.myList(id);
        return list;
    }
}
